<template>
  <div class="configure--parking">
    <el-form :model="formData" label-width="50px">

      <el-form-item label="姓名:">
        <el-input v-model="formData.username"></el-input>
      </el-form-item>

      <el-form-item label="电话:">
        <el-input v-model="formData.telephone"></el-input>
      </el-form-item>

      <el-form-item label="店铺:">
        <div>
          <div v-for="(item,index) in shopLists" class="park-name">
            {{item.shopName}}
            <img class="delate" src="../../../../assets/delate.png" @click="deleteParking(index)">
          </div>
        </div>
        <el-select v-model="formData.options" @change="changParking">
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.shopName"
            :value="item" />
        </el-select>
      </el-form-item>
    </el-form>
    
    <p style="text-align: center;">
      <el-button size="mini" type="primary" @click="submit">提交</el-button>
    </p>
  </div>
</template>

<script>
  export default {
    props: ['row'],
    data() {
      return {
        formData: {
          shopIds: []
        },
        shopLists: [],
        options: []
      }
    },
    mounted() {
      this.formData.managerId = this.row.id;
      this.formData.telephone = this.row.telephone;
      this.formData.username = this.row.username;
      if(this.row.shopList) {
        this.shopLists = this.row.shopList;
      }
      this.getParkingList();
    },
    methods: {
      getParkingList() {
        this.$axios({
          method: 'get',
          url: '/shop/shop-info/get-no_manager'
        }).then((res) => {
          if(res.code == 200) {
            this.options = res.data;
          }
        })
      },

      changParking(e) {
        this.shopLists.push(e)
      },

      deleteParking(index) {
        this.shopLists.splice(index,1)
      },

      submit() {
        if(this.shopLists) {
          this.shopLists.forEach(item => {
            this.formData.shopIds.push(item.id)
          })
        }
        this.$axios({
          method: 'post',
          url: '/shop/shop-manager/update-manager',
          data: this.formData
        }).then((res) => {
          if(res.code == 200) {
            this.$emit('closeDialog',false);
            this.$message.success('配置商户信息成功');
            this.$emit('refresh')
          }
        })
      }
    }
  }
</script>

<style scoped>
  .el-form {
    display: inline-block;
    margin-left: 50%;
    transform: translateX(-50%);
  }

  .el-input {
    width: 200px;
  }

  .park-name {
    background-color: #21B5FF;
    padding: 0 8px;
    border-radius: 8px;
    color: #FFF;
    display: inline-block;
    position: relative;
    margin-bottom: 10px;
    margin-right: 10px;
    font-size: 14px;
  }

  .delate {
    height: 16px;
    width: 16px;
    position: absolute;
    top: -5px;
    right: -5px;
  }


</style>
